def p(a):    
    if ad == 1: return False    
    test = True    
    ky = ad - 1    
    while ky > 1:    
        if not ad % ky:    
            test = False                
            break    
        ky -= 1        
    return test   
      
n = input()  
l = []  
for i in range(len(n)):  
    for ky in range(i + 1,len(n) + 1):  
        ad = int(n[i:ky]) 
        if p(ad):  
            l += [ad]  
print(max(l) if l else 0)
